package com.android.questions.ui.adapter;

import android.widget.TextView;

import androidx.annotation.NonNull;

import com.android.questions.R;
import com.android.questions.entity.HelpEntity;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

/**
 * FileName: HelpAdapter
 * Author: admin
 * Date: 2021/11/15 13:15
 * Description:
 */
public class HelpAdapter extends BaseMultiItemQuickAdapter<HelpEntity, BaseViewHolder> {

    public HelpAdapter() {
        super(null);
        addItemType(HelpEntity.TYPE_RECEIVE, R.layout.item_help_receive);
        addItemType(HelpEntity.TYPE_SEND, R.layout.item_help_send);
    }

    @Override
    protected int getDefItemViewType(int position) {
        if ((getData().get(position).getReceiveEntity() != null)) {
            return HelpEntity.TYPE_RECEIVE;
        } else if (getData().get(position).getSendEntity() != null) {
            return HelpEntity.TYPE_SEND;
        }
        return position;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, HelpEntity chatEntity) {
        switch (getItemViewType(getItemPosition(chatEntity))) {
            case HelpEntity.TYPE_RECEIVE:
                TextView tvDataReceive = baseViewHolder.getView(R.id.tvDataReceive);
                tvDataReceive.setText(chatEntity.getReceiveEntity().getChatContent());
                break;
            case HelpEntity.TYPE_SEND:
                TextView tvDataSend = baseViewHolder.getView(R.id.tvDataSend);
                tvDataSend.setText(chatEntity.getSendEntity().getChatContent());
                break;
        }
    }
}